package com.bawei.fuxi.ui.home;

import androidx.appcompat.app.AppCompatActivity;
import top.littlefogcat.danmakulib.danmaku.Danmaku;
import top.littlefogcat.danmakulib.danmaku.DanmakuManager;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bawei.fuxi.R;
import com.bawei.fuxi.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

@Route(path = "/app/video")
public class VideoActivity extends AppCompatActivity {
    @Autowired
    VideoEntity.DataBean video;//接受数据还需要注入
    private StandardGSYVideoPlayer gsy;
    private FrameLayout danmuView;
    private EditText et;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        ARouter.getInstance().inject(this);
        Toast.makeText(this, ""+video.getCaption(), Toast.LENGTH_SHORT).show();
        gsy = (StandardGSYVideoPlayer) findViewById(R.id.gsy);
        danmuView = (FrameLayout) findViewById(R.id.danmu_view);
        et = (EditText) findViewById(R.id.et);
        //视频
        gsy.setUp(video.getVideopath(),true,video.getAuthname());
        gsy.startPlayLogic();
        //全屏
        gsy.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gsy.startWindowFullscreen(VideoActivity.this,true,true);
            }
        });
    }
    //发送弹幕
    public void sendDanmaKu(View view) {
        //初始化
        DanmakuManager.getInstance().init(this,danmuView);
        //实例化弹幕对象
        Danmaku danmaku = new Danmaku();
        danmaku.text = et.getText().toString();
        danmaku.size = 50;
        danmaku.color = "#FF6200EE";
        //发送弹幕
        DanmakuManager.getInstance().send(danmaku);
    }



    //继续播放
    @Override
    protected void onResume() {
        super.onResume();
        GSYVideoManager.onResume(true);
    }
    //暂停
    @Override
    protected void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }
    //销毁
    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoManager.releaseAllVideos();//释放资源，解决内存泄漏问题
    }
}